package org.example.javawebday1.controller;

import org.example.javawebday1.pojo.Result;
import org.example.javawebday1.utils.OSSOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController {
    @Autowired
    private OSSOperation ossOperation;

    @PostMapping("/upload")
    public Result upload(@RequestParam("file") MultipartFile file) {
        try {
            return Result.success(ossOperation.fileUpload(file));
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }
}
